/**
 * @param {string} s
 * @param {character} c
 * @return {number[]}
 */
 var shortestToChar = function(s, c) {
  const ret = new Array(s.length).fill(Infinity);
  let last = -1;
  for(let i=0;i < s.length;i++) {
      if(s[i] === c) {
          if(last === -1) {
              let g = i;
              let v = 0;
              while (g >= 0) {
                  ret[g] = v;
                  v++;
                  g--;
              }
          } else {
              let g = i;
              let v = 0;
              while (v < ret[g]) {
                  ret[g] = v;
                  v ++;
                  g --;    
              }
          }
          last = i;
      } else if (last != -1) {
          ret[i] = i - last;
      }
  }
  return ret;
};